package com.sservice.web.controller.common;

import com.google.zxing.WriterException;
import com.sservice.base.constant.MatrixToImageWriter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by suweiming on 2018/12/28.
 */
@Controller
public class QrcodeController {
    /**
     * 生成二维码
     *
     * @param url      二维码内容
     * @param response
     * @throws IOException
     * @throws WriterException
     */
    @ResponseBody
    @RequestMapping(value = "/getQrcode", method = RequestMethod.GET)
    public void getQrcode(String url, HttpServletResponse response) throws IOException, WriterException {
        MatrixToImageWriter.createRqCode(url, 400, 400, response.getOutputStream());
        response.flushBuffer();
    }
}
